
angular.module('SpecialJudge')

.controller('SpecialJudge.DetailCtrl', ['$scope', '$ionicHistory', 'SpecialJudgeMaster', 'imanDialog', 'SpecialJudgeHttpUtil', 
    function ($scope, $ionicHistory, SpecialJudgeMaster, imanDialog, SpecialJudgeHttpUtil) {
        $scope.data = {
            badDetail: {},
            description: ''
        };

        $scope.showRemark = function () {
            imanDialog.alert($scope.data.badDetail.Remark || ' ', '备注');
        };
        $scope.doJudge = function (qcStatus, qcStatusName) {
            imanDialog.confirm('确定' + qcStatusName + '?', '品质特裁确认').then(function (btn) {
                if (btn) {
                    var barcode = SpecialJudgeMaster.getActiveMasterCode();
                    SpecialJudgeHttpUtil.doJudge(barcode, qcStatus).then(function () {
                        imanDialog.toastBottom('品质特裁成功');
                        if ($ionicHistory.backView()) {
                            $ionicHistory.goBack();
                        }
                    });
                }
            });
        };

        $scope.$on('$ionicView.afterEnter', function () {
            SpecialJudgeMaster.getActiveMaster().then(function (detail) {
                $scope.data.badDetail = detail;
            });
        });
        $scope.$on('$ionicView.beforeLeave', function () {
            SpecialJudgeMaster.setActiveMaster(null);
            SpecialJudgeMaster.setActiveMasterCode(null);
        });
    }
]);